package com.tjetc.view.impl;

import com.tjetc.constant.CommonConstant;
import com.tjetc.exception.MessageException;
import com.tjetc.pojo.dto.ReviewDTO;
import com.tjetc.utils.ScannerUtils;
import com.tjetc.view.CommentPage;

import java.time.LocalDateTime;

/**
 * @Author: itda
 * @Date: 2024/5/11 19:16
 * @Description: CommentPageImpl
 */
public class CommentPageImpl implements CommentPage {
    @Override
    public int show(){
        while (true) {
            try {
                System.out.println("1.查看评论");
                System.out.println("2.查看评级");
                System.out.println("3.返回");
                System.out.println("请输入:");
                int option = ScannerUtils.sc.nextInt();
                if (option<1||option>3){
                    throw new MessageException(CommonConstant.COMMAND_ERROR);
                }
                return option;
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }
    }

    @Override
    public ReviewDTO comment(Long hotelId) {
        System.out.println("请输入评论内容:");
        String content = ScannerUtils.sc.next();
        System.out.println("请输入评级(1-5):");
        short rating = ScannerUtils.sc.nextShort();
        return ReviewDTO.builder()
                .hotelId(hotelId)
                .comment(content)
                .rating(rating)
                .commentTime(LocalDateTime.now())
                .build();
    }
}
